package com.carkeeper.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.carkeeper.pojo.Blog;
import com.carkeeper.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/blog")
public class BlogController {

    @Autowired
    BlogService blogService;

    @PostMapping
    public Boolean addBlog(@RequestBody Blog blog) {
        return blogService.addBlog(blog);
    }

    //修改、发布、取消发布
    @PutMapping
    public Boolean updateBolg(@RequestBody Blog blog) {
        return blogService.updateBlog(blog);
    }

    @GetMapping(value = "/{id}")
    public Blog queryById(long id) {
        return blogService.queryById(id);
    }

    @GetMapping
    public IPage<Blog> queryBlogPage(@RequestBody(required = false) Blog blog, int pageNum, int pageSize) {
        IPage<Blog> blogIPage = blogService.queryBlogPage(pageNum, pageSize, blog);
        return blogIPage;
    }
}
